package is.ru.honn.rumblr.data;

import is.ru.honn.rumblr.domain.User;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author Stefan Gunnarsson
 * @Version 0.1 aplha
 */
public class UserRowMapper  implements ParameterizedRowMapper<User>
{
    //Creates a user and adds in the details from ResultSet then returns the user.
    public User mapRow(ResultSet rs, int rowNum) throws SQLException
    {
       User user = new User();
       try
       {
           user.setUsername(rs.getString(1));
           user.setName(rs.getString(2));
       }
       catch (Exception ex)
       {
            String msg = "Unable to create post from ResultSet";
            throw new SQLException(msg);
       }
       return user;
    }

}
